<template>
	<view>
		<!-- :style="{height:screenHeight+'px'}" -->
		<view class="content" >
			<view class="information">
				<view>
					<view>发起人信息</view>
					<view>^</view>
				</view>
				<view v-if="pagedata.mun">
					<view>流水号</view>
					<view>{{pagedata.mun}}</view>
				</view>
				<view v-if="pagedata.meeting_num">
					<view>流水号</view>
					<view>{{pagedata.meeting_num}}</view>
				</view>
				<view>
					<view>姓名</view>
					<view>{{pagedata.name}}</view>
				</view>
				<view>
					<view>部门</view>
					<view>{{pagedata.department_name}}</view>
				</view>
				<view>
					<view>岗位</view>
					<view>{{pagedata.post_name}}</view>
				</view>
				<view v-if="pagedata.applytime">
					<view>发起时间</view>
					<view>{{pagedata.applytime}}</view>
				</view>
				<view v-if="pagedata.meeting_todotime">
					<view>发起时间</view>
					<view>{{pagedata.meeting_todotime}}</view>
				</view>
				<view v-if="pagedata.approvaltime">
					<view>审批时间</view>
					<view>{{pagedata.approvaltime}}</view>
				</view>
				<view v-if="pagedata.meeting_agreetime">
					<view>审批时间</view>
					<view>{{pagedata.meeting_agreetime}}</view>
				</view>
			</view>
			<view class="details" v-if="leavestate==1" >
				<view>
					<view>申请信息</view>
					<view>^</view>
				</view>
				<view>
					<view>申请类型</view>
					<view><text>{{pagedata.type}}</text></view>
				</view>
				<view>
					<view>开始时间</view>
					<view><text>{{pagedata.starttime}}</text></view>
				</view>
				<view>
					<view>结束时间</view>
					<view><text>{{pagedata.endtime}}</text></view>
				</view>
				<view v-if="pagedata.type=='外勤'">
					<view>出差地点</view>
					<view><text>{{pagedata.out_place}}</text></view>
				</view>
				<view>
					<view>理由</view>
					<view><text>{{pagedata.content}}</text></view>
				</view>
			</view>
			
			<!-- 转岗-调薪 -->
			<view class="details" v-if="leavestate==2" >
				<view>
					<view>申请信息</view>
					<view>^</view>
				</view>
				<view>
					<view>申请类型</view>
					<view><text>{{pagedata.type}}</text></view>
				</view>
				<view v-if="pagedata.type=='调薪'">
					<view>当前薪资（元）</view>
					<view><text>{{pagedata.money}}</text></view>
				</view>
				<view v-if="pagedata.type=='调薪'">
					<view>期望薪资（元）</view>
					<view><text>{{pagedata.newmoney}}</text></view>
				</view>
				<view v-if="pagedata.type=='转岗'">
					<view>新部门</view>
					<view><text>{{newpart}}</text></view>
				</view>
				<view v-if="pagedata.type=='转岗'">
					<view>新岗位</view>
					<view><text>{{newjobs}}</text></view>
				</view>
				<view>
					<view>理由</view>
					<view><text>{{pagedata.content}}</text></view>
				</view>
			</view>
			<!-- 会议 -->
			<view class="details" v-if="pagedata.meeting_num" >
				<view>
					<view>申请信息</view>
					<view>^</view>
				</view>
				<view>
					<view>申请类型</view>
					<view><text>会议</text></view>
				</view>
				<view>
					<view>流水号</view>
					<view><text>{{pagedata.meeting_num}}</text></view>
				</view>
				<view>
					<view>会议标题</view>
					<view><text>{{pagedata.meeting_tit}}</text></view>
				</view>
				<view>
					<view>开始时间</view>
					<view><text>{{pagedata.meeting_startime}}</text></view>
				</view>
				<view >
					<view>结束时间</view>
					<view><text>{{pagedata.meeting_endtime}}</text></view>
				</view>
				<view>
					<view>会议时长（小时）</view>
					<view><text>{{meeting_length}}</text></view>
				</view>
				<view >
					<view>参会人数（人）</view>
					<view><text>{{pagedata.meeting_pernum}}</text></view>
				</view>
				<view >
					<view>会议内容</view>
					<view><text>{{pagedata.meeting_cont}}</text></view>
				</view>
			</view>
		</view>
		
		<view class="footer" v-if="state=='待办'">
			<button @click="submit('同意')">同意</button>
			<button @click="submit('不同意')" type="warn">不同意</button>
		</view>
	</view>
<!-- 	<uni-popup ref="popup" type="dialog">
		<uni-popup-dialog mode="input" message="成功消息" :duration="2000" :before-close="true" @close="close" @confirm="confirm"></uni-popup-dialog>
	</uni-popup> -->
</template>

<script>
	import http from '../../utils/http.js'
	import store from '~@/store/index.js'
	import {
		computed,
		reactive,
		toRefs,onMounted,
	} from 'vue';
	export default {
		setup() {
			let data = reactive({
				pagedata:store.state.zengjiayu.tododata,
				leavestate:0,
				newpart:'',
				newjobs:'',
				meeting_length:'',
				mysetInterval:'',
				state:store.state.zengjiayu.todostate,
				// screenHeight:"",
				// setheight:()=>{
				// 	uni.getSystemInfo({
				// 		success:function(res){
				// 			data.screenHeight=res.windowHeight-res.
				// 			console.log(res.windowHeight)
				// 		}
				// 	})
				// },
				goback:()=>{
					var pages=getCurrentPages()
					var beforepages=pages[pages.length-2]
					uni.navigateBack({
						success:function(){
							beforepages.onLoad()
							clearInterval(data.mysetInterval)
						}
					})
				},
				submit:(a)=>{
					let mytime=new Date()
					let time=mytime.toLocaleDateString().replace('/', '-').replace('/', '-')+' '+mytime.getHours()+':'+mytime.getMinutes()+':'+mytime.getSeconds()
						if(data.pagedata.meeting_num){
							http({
								url:'/Personalcenter/todo/change2',
								data:{
									time:time,
									agree:a,
									id:data.pagedata.meeting_id,
								}
							}).then((res3)=>{
							})
						};
						if(data.pagedata.mun){
							http({
								url:'/Personalcenter/todo/change1',
								data:{
									time:time,
									agree:a,
									mun:data.pagedata.mun
								}
							}).then((res)=>{
								if(data.pagedata.type=='调薪'&& a=='同意'){
									http({
										url:'/Personalcenter/todo/changeSalary',
										data:{
											money:data.pagedata.newmoney,
											id:data.pagedata.apply_name,
										}
									}).then((res2)=>{
										console.log(res2.data.msg)
									})
								}
								if(data.pagedata.type=='转岗'&& a=='同意'){
									http({
										url:'/Personalcenter/todo/changeJob',
										data:{
											jobs:data.pagedata.newjobs,
											id:data.pagedata.apply_name,
										}
									}).then((res3)=>{
										console.log(res3.data.msg)
									})
								}
								uni.showToast({
									title:'提示',
									duration: 7000,
									success() {
										data.mysetInterval=setInterval(()=>{
											data.goback()
										},1000)
										// data.goback()
									}
								})
							// data.goback()
							 // this.$refs.popup.open()
						})
						}
				},
				setlength:()=>{
					if(data.pagedata.meeting_num){
						let date1 = new Date(data.pagedata.meeting_startime);
						let date2 = new Date(data.pagedata.meeting_endtime);
						let total = (date2.getTime() - date1.getTime()) / 1000 / 60 / 60;
						data.meeting_length = total
					}	
				},
				getdata:()=>{
					http({
						url:'/Personalcenter/post/get',
						data:{
							postname:data.pagedata.newjobs
						}
					}).then((res)=>{
							 data.newpart=res.data.data[0].department_name
							 data.newjobs=res.data.data[0].post_name
					})
				}
			})
			onMounted(()=>{
				if(data.pagedata.type=='事假'||data.pagedata.type=='年假'||data.pagedata.type=='病假'||data.pagedata.type=='外勤'){
					data.leavestate=1
				}else if(data.pagedata.type=='调薪'||data.pagedata.type=='转岗'){
					data.leavestate=2
				}
				if(data.pagedata.newjobs){
					data.getdata()
				}
				data.setlength()
				// data.setheight()
				console.log(store.state.zengjiayu.tododata,8)
			})
			return {
				...toRefs(data)
			}
		}
	}
</script>

<style scoped lang="scss">
 .header {
	 text-align: center;
	 padding: 20rpx 0;
	 background-color: #FFFFFF;
 }
 .content {
	 height: 100%;
	 background-color: #F2F2F2;
	 padding: 30rpx;
	 .details {
		 margin-top: 30rpx;
		 text-align: left;
	 }
	 text{
		 color: #999999;
	 }
 }
 .information>view,.details>view {
	 margin: 0 30rpx;
	 padding: 20rpx 0;
 }
 .information>view:not(:first-child) {
	 display: flex;
	 view {
		 flex: 1;
	 }
 }
 .information>view:not(:last-child),
 .details>view:not(:last-child){
	 border-bottom: 1px solid #F6F6F6;
 }
 .information>view:not(:first-child)>view:first-child,
 .details>view:not(:first-child)>view {
 	 color: #566068;
 }
 .information>view:not(:first-child)>view:last-child,
 .details>view:not(:first-child)>input{
	 color: #999999;
 }
 .information>view:first-child,
 .details>view:first-child {
	 display: flex;
	 justify-content: space-between;
 }
 .content>view {
	 background-color: #fff;
	 border-radius: 20rpx;
 }
 .details>view:not(:first-child) {
	 display: flex;
	 
	 view {
		 flex: 1;
	 }
	 picker {
		 margin-left: 90rpx;
		 flex: 2;
		 color: #999999;
	 }
 }
 .footer {
	 background-color: #fff;
	 display: flex;
	 justify-content: space-around;
	 padding: 20rpx 0;
	 button {
		 width: 320rpx;
		 height: 80rpx;
		 line-height: 80rpx;
		 text-align: center;
		 font-weight: 300;
		 color: #fff;
		 background-color: #2D8CF0;
	 }
 }
</style>